package bishi.alibaba;

/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2020/3/25  10:31
 */
public class _34 {
    public static int solution(int[][] m) {
        int hang = m.length;
        int lie = m[0].length;
        int[][] daan = new int[hang][lie];
        for (int i = 0; i < hang; i++) {
            for (int j = 0; j < lie; j++) {
                if (i == 0 && j == 0) {
                    daan[0][0] = m[0][0];
                } else if (i!=0&&j!=0) {
                    daan[i][j] = m[i][j] + Math.min(daan[i - 1][j], daan[i][j - 1]);
                } else if (i==0&&j!=0) {
                    daan[i][j] = m[i][j]+daan[i][j-1];
                }else if (i!=0&&j==0){
                    daan[i][j] = m[i][j]+daan[i-1][j];
                }
            }
        }
        return daan[hang - 1][lie - 1];
    }

    public static void main(String[] args) {
        int[][] m = {{4, 1, 5, 3}, {3, 2, 7, 7}, {6, 5, 2, 8}, {8, 9, 4, 5}};
        System.out.println(solution(m));
    }
}
